package com.shanzmoo.db.stm.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.shanzmoo.db.stm.entity.StmSysRoleMenuEntity;
import com.shanzmoo.db.stm.entity.vo.StmSysRoleMenuVO;
import com.shanzmoo.db.stm.entity.query.StmSysRoleMenuQuery;
import com.shanzmoo.db.stm.mapper.StmSysRoleMenuMapper;
import com.shanzmoo.db.stm.service.IStmSysRoleMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shanzmoo.db.sys.entity.RoleMenuEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 仓储用户系统角色菜单关联表 服务实现类
 *
 * @author Gzhao 2021-03-10
 */
@Service
public class StmSysRoleMenuServiceImpl extends ServiceImpl<StmSysRoleMenuMapper, StmSysRoleMenuEntity>
        implements IStmSysRoleMenuService {

    @Override
    public void saveRoleMenuIds(Integer roleId, List<Integer> menuIds) {
        baseMapper.deleteByRoleId(roleId);

        if (CollectionUtil.isEmpty(menuIds)) {
            return;
        }
        List<RoleMenuEntity> roleMenuEntityList = menuIds.stream().map(menuId -> {
            return new RoleMenuEntity(roleId, menuId);
        }).collect(Collectors.toList());
        baseMapper.insertBatch(roleMenuEntityList);
    }
}
